package com.webvolcano.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class WC {

	public static int wc(String path) throws IOException {
		int i = 0;
		BufferedReader r = new BufferedReader(new FileReader(new File(path)));
		while (r.readLine() != null) {
			i++;
		}
		return i;
	}

	public static int wc(String path, String pattern) throws IOException {
		int i = 0;
		BufferedReader r = new BufferedReader(new FileReader(new File(path)));
		String line = null;
		String prevLine = null;
		while ((line = r.readLine()) != null) {
			// System.out.println(line);

			if (line.contains(pattern)) {
				i++;
			}
			prevLine = line;
		}
		return i;
	}

	public static void main(String[] args) throws Exception {
//		System.out.println(new WC().wc("c:/temp/dp_al22.txt",
//				"dealPlyBackground.html"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "noexisting.js"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "noexisting.jpg"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "=h1"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "=h2"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "=h3"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "=h4"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "=h5"));
		System.out.println(new WC().wc("C:\\temp\\s3.al.txt", "version=1039"));
		System.out.println(new WC().wc("C:\\temp\\s3.al.txt", "ver=10.39"));
		System.out.println(new WC().wc("C:\\temp\\s3.al.txt", "ver=10.38"));		
		System.out.println(new WC().wc("C:\\temp\\s3.al.txt", "dealPlyBackground.html"));
//		System.out.println(new WC().wc("C:\\temp\\s3.al.1230.txt", "cb=1"));
		
		
		
		
		
		// System.out.println(new WC().wc("c:/temp/dp_al.txt"));

	}
}
